from datetime import datetime

from pydantic import BaseModel, ConfigDict, Field
from pydantic.alias_generators import to_camel
from typing import Optional, List
from module_admin.annotation.pydantic_annotation import as_query
from decimal import Decimal



class PriceModel(BaseModel):
    """
    每日销售价记录表对应pydantic模型
    """

    model_config = ConfigDict(alias_generator=to_camel, from_attributes=True)

    purchase_price_id: Optional[str] = Field(default=None, description='记录ID')
    year: Optional[int] = Field(default=datetime.today().year, description='数据年份')
    create_by: Optional[str] = Field(default=None, description='发布人')
    create_time: Optional[datetime] = Field(default=None, description='发布时间')
    price: Optional[Decimal] = Field(default=None, description='销售单价')
    purchase_date: Optional[int] = Field(default=None, description='销售日期')
    update_by: Optional[str] = Field(default=None, description='更新人')
    update_time: Optional[datetime] =  Field(default=None, description='更新时间')
    product_size: Optional[str] = Field(default=None, description='产品规格')
    product_area_id: Optional[int] = Field(default=None, description='产区id')
    product_area: Optional[str] = Field(default=None, description='产区')
    effective_time: Optional[datetime] = Field(default=None, description='生效时间')
    expiration_time: Optional[datetime] = Field(default=None, description='失效时间')
    memo: Optional[str] = Field(default=None, description='备注')



class PriceQueryModel(BaseModel):
    """
    每日采购价记录不分页查询模型
    """
    model_config = ConfigDict(alias_generator=to_camel, from_attributes=True)
    year: Optional[int] = Field(default=datetime.today().year, description='数据年份')
    product_size: Optional[List[str]] = Field(default=None, description='产品规格')
    product_area_id: Optional[str] = Field(default=None, description='产区id')
    price: Optional[Decimal] = Field(default=None, description='收购单价')



@as_query
class PricePageQueryModel(PriceQueryModel):
    """
    每日采购价记录分页查询模型
    """
    page_num: int = Field(default=1, description='当前页码')
    page_size: int = Field(default=10, description='每页记录数')


class DeletePriceModel(BaseModel):
    """
    删除每日采购价记录模型
    """

    model_config = ConfigDict(alias_generator=to_camel)

    record_ids: str = Field(description='需要删除的记录IDs')


@as_query
class CalculatePriceQueryModel(BaseModel):
    """
    计算销售价模型
    """
    model_config = ConfigDict(alias_generator=to_camel, from_attributes=True)

    packaging_id: Optional[int] = Field(default=None, description='包装方式记录id')
    year: Optional[int] = Field(default=None, description='数据年份')
    as_id: Optional[int] = Field(default=None, description="账套Id")
    single_price: Optional[Decimal] = Field(default=0, description='果品单价（元/斤）')

    page_num: int = Field(default=1, description='当前页码')
    page_size: int = Field(default=10, description='每页记录数')

class SalePriceDetailModel(BaseModel):
    """
    销售价格明细模型
    """
    model_config = ConfigDict(alias_generator=to_camel, from_attributes=True)

    packaging_id: Optional[int] = Field(default=None, description='包装方式记录id')
    materials_cost: Optional[Decimal] = Field(default=None, description='包材费')
    chilling_fee: Optional[Decimal] = Field(default=None, description='人工及打冷费')
    product_id: Optional[int] = Field(default=None, description='商品Id')
    product_name: Optional[str] = Field(default=None, description='商品名称')
    product_weight: Optional[Decimal] = Field(default=None, description='商品重量（斤）')
    year: Optional[int] = Field(default=None, description='数据年份')
    as_id: Optional[int] = Field(default=None, description="账套Id")
    single_price: Optional[Decimal] = Field(default=0, description='果品单价（元/斤）')
    total_price:  Optional[Decimal] = Field(default=0, description='销售单价（元/件）')
    fruit_total:  Optional[Decimal] = Field(default=0, description='果品单件总价（元/件）')
    chilling_fee_total:  Optional[Decimal] = Field(default=0, description='人工和打冷单件总价（元/件）')

